package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/category")
@Api(tags = "分类相关接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    @ApiOperation("新增分类信息接口")
    public Result save(CategoryDTO categoryDTO){
        log.info("新增分类信息:{}",categoryDTO);
        categoryService.savecategory(categoryDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("分类信息分页接口")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类信息分页:{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("分类启用或禁止接口")
    public Result<String> startorStop(@PathVariable Integer status,Long id){
        log.info("分类启用或禁止接口{},{}",status,id);
        categoryService.startorStop(status,id);
        return Result.success();
    }
    @PutMapping
    @ApiOperation("修改分类接口")
    public Result<String> updatecategory(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类：{}",categoryDTO);
        categoryService.updatecategory(categoryDTO);
        return Result.success();
    }





}
